<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" template="/templates/layout.xhtml">

	<ui:define name="ptitle">平台功能权限管理</ui:define>
	<ui:define name="pcontent">
		<p:tabView id="tabview" >
		    <p:ajax event="tabChange" listener="#{sysResourceMB.onTabChange}" update=":tabview:frm2"/>	
			<p:tab id="tab1" title="资源权限管理">
				<h:form id="frm1">
					<p:growl id="msgs1" showDetail="true" />
					<p:panel id="resourcePanel" header="资源信息维护"
						style="margin-bottom:5px"
						footer="资源信息是可以作为访问控制的单元，可以是功能页面、按钮、图片文件资源等。一种权限可以包含一种或多种资源的组合。每次增加资源ID后，其对应的菜单ID和父菜单ID都是默认设置为资源ID的，需要在菜单权限维护中修改对应菜单ID的父菜单ID以便在同一菜单项下。">
						<h:panelGrid columns="8" cellspacing="10">							
							<p:outputLabel value="资源类别" />
							<p:selectOneMenu value="#{sysResourceMB.sysResource.category}"
								style="width:125px;" required="true" requiredMessage="资源类别必须输入">
								<f:selectItem  itemLabel="功能页面"	itemValue="1" />
								<f:selectItem  itemLabel="操作按钮"	itemValue="2" />
								<f:selectItem  itemLabel="图片资源"	itemValue="3" />							
								<f:selectItem  itemLabel="目录文件"	itemValue="4" />							
							</p:selectOneMenu>		
							<p:outputLabel value="资源ID" />
							<p:inputText  value="#{sysResourceMB.sysResource.id}" required="true" requiredMessage="资源编号必须输入"/>
							<p:outputLabel value="资源名称" />
							<p:inputText value="#{sysResourceMB.sysResource.name}" required="true" requiredMessage="资源名称必须输入"/>
							<p:outputLabel value="资源图标" />
							<p:inputText value="#{sysResourceMB.sysResource.icon}" required="true" requiredMessage="资源图标必须输入"/>					
						</h:panelGrid>
						<h:panelGrid columns="4" cellspacing="10">
							<p:outputLabel value="资源路径" />
							<p:inputText value="#{sysResourceMB.sysResource.source}" required="true" requiredMessage="资源路径必须输入" style="width:600px"/>
						
							<p:commandButton value="新增资源提交"	icon="ui-icon-check" 
								action="#{sysResourceMB.commitAction}" update=":tabview:frm1">
							</p:commandButton>	
						</h:panelGrid>
						<p:dataTable id="rdt" var="row" resizableColumns="true" liveResize="true" 
							value="#{sysResourceMB.voSysResource}" editable="true"
							style="margin-bottom:20px" >
							
							<p:ajax event="rowEdit" listener="#{sysResourceMB.onRowEdit}"
								update=":tabview:frm1:msgs1" />
							<p:ajax event="rowEditCancel"	listener="#{sysResourceMB.onRowCancel}"
								update=":tabview:frm1:msgs1" />

							<p:column headerText="资源类别">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.category == 1 ? '功能页面' : (row.category == 2 ? '操作按钮' : (row.category == 3 ? '图片资源' : row.category))}" />
									</f:facet>
									<f:facet name="input">
										<h:outputText value="#{row.category == 1 ? '功能页面' : (row.category == 2 ? '操作按钮' : (row.category == 3 ? '图片资源' : row.category))}" />										
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="资源ID" sortBy="#{row.id}">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.id}" />
									</f:facet>
									<f:facet name="input">
										<h:outputText id="modelInput" value="#{row.id}"
											style="width:100%" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="资源名称">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.name}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{row.name}" style="width:100%"
											label="资源名称" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="资源路径">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.source}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{row.source}" style="width:100%"
											label="资源路径" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="资源图标">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.icon}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{row.icon}" style="width:100%"
											label="资源图标" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column style="width:32px">
								<p:rowEditor />
							</p:column>
						</p:dataTable>

					</p:panel>
				</h:form>
				
			</p:tab>

			<p:tab id="tab2" title="菜单权限管理">
				<h:form id="frm2">
					<p:growl id="msgs2" showDetail="true" />
					<p:panel id="resourcePanel" header="菜单权限维护"
						style="margin-bottom:5px"
						footer="菜单权限是设置菜单项目对应的功能权限。点击单元格可以进行修改。菜单ID和资源ID相同且不能修改。每次增加资源ID后，需要修改对应菜单ID的父菜单ID。如果菜单ID的父菜单ID相同则显示为一级菜单，不能链接新功能。">									 
						<p:dataTable id="mdt" var="mrow" resizableColumns="true" liveResize="true" 
							value="#{sysResourceMB.voSysMenus}" editable="true" editMode="cell"
							style="margin-bottom:20px" >

							<p:ajax event="cellEdit" listener="#{sysResourceMB.onCellEdit}" update=":tabview:frm2:msgs2" />
							<p:column headerText="菜单ID" sortBy="#{mrow.id}">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{mrow.id}" style="width:60px"/>
									</f:facet>
									<f:facet name="input">
										<h:outputText value="#{mrow.id}" style="width:60px"/>
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column headerText="资源权限ID">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{mrow.sysAuthority.id}" />
									</f:facet>
									<f:facet name="input">
										<h:outputText value="#{mrow.sysAuthority.id}" style="width:100%"
											label="资源ID" />
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column headerText="父菜单ID">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{mrow.pid}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText id="modelInput" value="#{mrow.pid}"
											style="width:100%" label="父菜单ID" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="菜单名称">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{mrow.name}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{mrow.name}" style="width:100%"
											label="菜单名称" />
									</f:facet>
								</p:cellEditor>
							</p:column>

							<p:column headerText="排序码">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{mrow.orderby}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{mrow.orderby}" style="width:100%"
											label="排序码" />
									</f:facet>
								</p:cellEditor>
							</p:column>

						</p:dataTable>

					</p:panel>
				</h:form>

			</p:tab>

		</p:tabView>
	</ui:define>
</ui:composition>

